from web import models
from django.db.models import Q
from utils.bootstrap import BootstrapModelForm,BootStrap

class WikiAddModelForm(BootstrapModelForm):
    def __init__(self,request,*args,**kwargs):
        super().__init__(*args,**kwargs)
        self.request = request
        self.fields['parent'].queryset = models.Wiki.objects.filter(Q(project=self.request.tracer.project))
        # 或者用下面的方法
        # total_data_list = [("", "请选择"), ]
        # data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id', 'title')
        # total_data_list.extend(data_list)
        # self.fields['parent_id'].choices = total_data_list
    class Meta:
        model = models.Wiki
        exclude = ['project','depth',]
